package com.weiyu.bultrasound.core.controller;

import com.weiyu.bultrasound.core.model.common.JsonResult;
import com.weiyu.bultrasound.core.model.request.LoginRequest;
import com.weiyu.bultrasound.core.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 *@description 登录管理
 *@author abner chow
 *@date 2019-08-13 16:30
 */

@Api(description = "登录Api", tags = "LoginController", basePath = "/login")
@RestController
@RequestMapping(value = "/v1/login", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class LoginController {

    private static final Logger logger = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    LoginService loginService;


    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "token", required = false, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "【移动端】登录", notes = "返回操作标识")
    @RequestMapping(value = "login4Mobile", method = RequestMethod.POST)
    public JsonResult<Map> login4Mobile(@RequestBody LoginRequest loginRequest) {
        if (null != loginRequest && StringUtils.hasText(loginRequest.getHandultsn())) {
            logger.info(loginRequest.toString());
            return JsonResult.getResult4Map(loginService.login4Mobile(loginRequest.getHandultsn()));
        }else {
            Map map = null;
            return JsonResult.getResult4Map(map);
        }
    }


    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "token", required = false, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "【后台】登录", notes = "返回操作标识")
    @RequestMapping(value = "login4Web", method = RequestMethod.POST)
    public JsonResult<Map> login4Web(@RequestBody LoginRequest loginRequest) {
        if (null != loginRequest) {
            logger.info(loginRequest.toString());
            return JsonResult.getResult4Map(loginService.login4Web(loginRequest));
        }else {
            Map map = null;
            return JsonResult.getResult4Map(map);
        }
    }

}
